//1.导入vue 和 vuerouter 的包
import Vue from 'vue'
import VueRouter from 'vue-router'
import IndexHome from '@/pages/index'
import UserInfo from '@/pages/userManage/userInfo'
import UserInput from '@/pages/fundManage/userInput'
import StageInfo from '@/pages/stageManage/stageInfo'
import DataSetting from '@/pages/backstageManage/dataSetting'
import Sites from '@/pages/backstageManage/sitesManage'
import Login from '@/pages/login'
import UserExcel from '@/pages/userManage/userExcel'
//import pathArr from '@/router/pathArr'

//2.调用vue.use() 函数，把 VueRouter 安装为 Vue 的插件
//vue.use()函数的作用，就是来安装插件的
Vue.use(VueRouter)

//3.创建路由的实例对象
const router = new VueRouter({
    routes: [
        //重定向规则,登录的路由规则
        {
            path: '/',
            redirect: '/login'
        },
        //后台的路由规则

        {
            path: '/login',
            name: 'Login',
            component: Login
        },
        {
            path: '/IndexHome',
            name: 'IndexHome',
            component: IndexHome
        },
        {
            path: '/UserInfo',
            name: 'UserInfo',
            component: UserInfo
        },
        {
            path: '/UserInput',
            name: 'UserInput',
            component: UserInput
        },
        {
            path: '/StageInfo',
            name: 'StageInfo',
            component: StageInfo
        },
        {
            path: '/DataSetting',
            name: 'DataSetting',
            component: DataSetting
        },
        {
            path: '/sites',
            name: 'Sites',
            component: Sites
        },
        {
            path: '/userExcel',
            name: 'userExcel',
            component: UserExcel
        }
    ],
    //去除#
    mode: "history"
})

router.beforeEach((to, from, next) => {
    if (to.path === '/login') return next()
    const tokenStr = window.sessionStorage.getItem('token')
    if (!tokenStr) return next('/login')
    next()
})

//4.向外共享路由的实例对象
export default router
